import LoginView from '@/views/LoginView.vue'
import ProductDetails from '@/views/Index/productDetails.vue'
import RegisterView from '@/views/RegisterView.vue'
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '@/views/Index/HomeView.vue'
import IndexLayout from '@/views/Index/layout.vue'
import QuervView from '@/views/score/QuervView.vue'
import ResultView from '@/views/score/ResultView.vue'
import MyView from '@/views/MyView.vue'
import { recordEnterPageStartTime, statisticsSource } from '@/utils/productDetailsUtils'

const router = createRouter
(
  {
    history: createWebHistory(),
    routes: 
    [
      {
        path: '/',
        component: IndexLayout,
        redirect: '/homeView',
        children:
        [
          {
            path: 'homeView',
            alias: '/home',
            name: 'homeView',
            component: HomeView,
          },
          {
            path: '/productDetails/:id',
            name: 'productDetails',
            component: ProductDetails,
            beforeEnter: (to, from) => 
            {
              statisticsSource(from.fullPath, to.fullPath)

              recordEnterPageStartTime()
            },
          },
        ]
      },
      {
        path: '/loginView',
        name: 'loginView',
        component: LoginView,
      },
      {
        path: '/myView',
        name: 'myView',
        component: MyView,
      },
      {
        path: '/registerView',
        name: 'registerView',
        component: RegisterView,
      },
      {
        path: '/quervView',
        component: QuervView,
      },
      {
        path: '/resultView/:studentId/:courseId',
        name: 'resultView',
        component: ResultView,
      },
    ],
  }
)

export default router
